# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document

class PaymentLedgerMappingItem(Document):
    def validate(self):
        """验证子表项的有效性"""
        self.validate_report_item()
    
    def validate_report_item(self):
        """确保报表项名称不为空且符合规范"""
        if not self.report_item:
            frappe.throw(_("Report Item cannot be empty for Account {0}").format(self.account))
        
        # 可选：限制报表项的特殊字符
        import re
        if not re.match(r'^[a-zA-Z0-9\s\-_]+$', self.report_item):
            frappe.throw(_("Report Item can only contain letters, numbers, spaces, hyphens and underscores"))
    